<?php

class AnnexesController extends AppController {

    var $name = 'Annexes';

    function index($predio) {
        $this->set('predio', $predio);
        $this->set('annexes', $this->Annex->find('all', array('conditions' => array('Annex.property_id' => $predio), 'fields' => array('Property.codigo', 'Annex.area', 'Annex.nombre', 'Annex.id', 'Annex.descripcion'))));
    }

    function add($predio) {
        $this->set('est', 0);
        if (empty($this->data)) {
            $this->data['Annex']['property_id'] = $predio;
        } else {
            if ($this->Annex->save($this->data)) {
                $this->Session->setFlash('Registro adicionado exitosamente');
                $this->redirect(array('controller' => 'Annexes', 'action' => 'index', $this->data['Annex']['property_id']));
            }else{
                
            }
        }
    }

    function edit($construccion) {
        $this->set('est', 0);
        if (empty($this->data)) {
            $this->Annex->recursive = -1;
            $this->data = $this->Annex->find('first', array('conditions' => array('Annex.id' => $construccion)));
        } else {
            if ($this->Annex->save($this->data)) {
                $this->Session->setFlash('Registro adicionado exitosamente');
                $this->redirect(array('controller' => 'Annexes', 'action' => 'index', $this->data['Annex']['property_id']));
            }else{
                $this->data['Annex']['id']=$construccion;
            }
        }
    }

    function delete($construccion, $predio) {
        if ($this->Annex->delete($construccion)) {
            $this->Session->setFlash('Construcción Borrada exitosamente');
            $this->setAction('index', $predio);
        }
    }

    function edit_valor($anexo) {
        $this->set('est', 0);
        if (empty($this->data)) {
            $this->Annex->recursive = -1;
            $this->data = $this->Annex->find('first', array('conditions' => array('Annex.id' => $anexo), 'fields' => array('Annex.valor_adoptado', 'Annex.id')));
        } else {
            if ($this->Annex->save($this->data)) {
                $this->Session->setFlash('Registro adicionado exitosamente');
                $this->redirect(array('controller' => 'PropertyAppraisals', 'action' => 'annexes_valor_index'));
            }else{
                $this->data['Annex']['id']=$anexo;
            }
        }
    }

}

?>